import java.util.*;
public class Test {
    public static void main1(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int left = 0;
        int right = 0;
        List<String> list = new LinkedList<>();
        while(right < str.length()){
            char ch  = str.charAt(right);
            if(left == right && ch == '"'){
                left++;
                right++;
                ch  = str.charAt(right);
                while(ch != '"'){
                    right++;
                    ch  = str.charAt(right);
                }
                list.add(str.substring(left, right));
                left = right + 1;
                if(left < str.length() && str.charAt(left) == ' '){
                    left = left + 1;
                }
                right = left;
                continue;
            }
            if(ch != ' '){
                right++;
            }else{
                list.add(str.substring(left, right));
                left = right + 1;
                right  = left;
            }
        }
        if(right == str.length()){
            list.add(str.substring(left, right));
        }


        System.out.println(list.size());
        for(String s : list){
            System.out.println(s);
        }
    }

    private static List<Integer> divisor(int n){
        List<Integer> list = new LinkedList<>();
        for(int i = 2; i <= Math.sqrt(n); i++){
            if(n % i == 0){
                list.add(i);
            }
        }

        return list;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Integer> list = null;
        int h = N;
        int t = N;
        int count = 0;
        while(t != M){
            list = divisor(t);
            if(list == null){
                System.out.println(-1);
                return;
            }
            for(int i = list.size() - 1; i >= 0; i--){
                t += list.get(i);
                count++;
                list = divisor(t);
                if(list == null){
                    t = h;
                    count--;
                }else{
                    break;
                }
            }

        }
        System.out.println(count);
    }
}
